home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: cwi.nl!dik
- From: dik@cwi.nl (Dik T. Winter)
- Subject: Re: Problem Negating an Unsigned Char
- Message-ID: <DnqMyr.4pF@cwi.nl>
- Sender: news@cwi.nl (The Daily Dross)
- Nntp-Posting-Host: chrysant.cwi.nl
- Organization: CWI, Amsterdam
- References: <Dnnros.Lq.0.-s@hkusuc.hku.hk> <4he27sINNdel@keats.ugrad.cs.ubc.ca>
- Date: Mon, 4 Mar 1996 10:11:15 GMT
-
- In article <4he27sINNdel@keats.ugrad.cs.ubc.ca> c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) writes:
- ...
- > >unsigned char a=0x11;
- > >unsigned char b=0xEE;
- ...
- > > if( a == ~b ) {
- ...
- > >The c remains unchange, while it changes to 1 if I cast the ~b to unsigned
- > >char as if( a == (unsigned char) ~b )
- >
- > The cast forces the integer value of ~b into an unsigned char, stripping
- > high-order bits. The above will work only on machines with eight bit chars.
- >
- > To make it portable, you must manually mask for the lower eight bits:
- >
- > if (a == (~b & 0xff))
-
- And how would this work on machines with other than eight bit chars?
- Casting to unsigned char will work regardless the number of bits in a char.
- --
- dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924098
- home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
-